import request from "@/axios/request";
import { defineStore } from "pinia";
import { store } from "./store";
import { ref } from "vue";

export const useDevToolsStore = defineStore("devTools", () => {
  /**
   * 加密字符串
   * @param {string} plainText 要加密的文本
   * @param {string} key 加密密钥(16/24/32字节)
   * @returns {Promise<string>} 加密后的Base64字符串
   */
  function encrypt(plainText, key) {
    return request.post({
      url: "/api/DevTools/Encrypt",
      method: "post",
      data: { plainText, key }
    });
  }

  /**
   * 解密字符串 
   * @param {string} plainText 要解密的Base64字符串
   * @param {string} key 解密密钥(16/24/32字节)
   * @returns {Promise<string>} 解密后的原始字符串
   */
  function decrypt(plainText, key) {
    return request.post({
      url: "/api/DevTools/Decrypt",
      method: "post", 
      data: { plainText, key }
    });
  }

  return {
    encrypt,
    decrypt
  };
});

export const useDevToolsWithOut = () => {
  return useDevToolsStore(store);
};
